package com.uidp.search;

import static com.uidp.hibernatelayer.ModulElementsDAO.ELEMENTNAME;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
import static org.hibernate.criterion.Restrictions.eq;

import com.acsior.sbc.exception.BusinessException;
import com.acsior.sbc.exception.SearchException;
import com.acsior.sbc.impl.hibernate.SearchHibernateBusinessObject;
import com.uidp.domain.ModulElements;
import com.uidp.hibernatelayer.ModulElementsDAO;
import com.uidp.hibernatelayer.ModulElementsVO;

public class ModulElementsSearch
		extends
		SearchHibernateBusinessObject<ModulElementsVO, ModulElementsDAO, ModulElements> {

	private ModulElements modulElCriteria;

	public ModulElementsSearch() throws BusinessException {
		super();
	}
	
	public ModulElementsSearch(String elementname) throws BusinessException {
		this.modulElCriteria.setElementname(elementname);
	}
	

	/** @see SearchObject#initialize() */
	@Override
	protected final void initialize() throws BusinessException {
		super.initialize();

		this.modulElCriteria = new ModulElements();
	}

	/** @see SearchHibernateBusinessObject#buildCriteria() */
	@Override
	protected void buildCriteria() throws SearchException {
		super.buildCriteria();
		if (isNotEmpty(getModulElCriteria().getElementname())) {
			getCriteria().add(eq(ELEMENTNAME, getModulElCriteria().getElementname()));
		}
	}

	@Override
	protected ModulElements createResultObject(ModulElementsVO d)
			throws BusinessException {
		return new ModulElements(d);
	}

	@Override
	protected Class<ModulElementsDAO> getDAOClass() {
		return ModulElementsDAO.class;
	}

	public ModulElements getModulElCriteria() {
		return modulElCriteria;
	}

	public void setModulElCriteria(ModulElements modulElCriteria) {
		this.modulElCriteria = modulElCriteria;
	}

}
